package com.xjw.tool;

import com.xjw.entity.ChessPoint;
import com.xjw.service.FiveChess;

import java.util.ArrayList;
import java.util.List;

/**
 * @author 徐军文
 * @since 2021/11/4 22:49
 */
public class ChessUtil {

    public static char getOtherColor(char chessColor){
        return chessColor == 'B' ? 'W':'B';
    }

    public static List<ChessPoint> getAroundChess(int row, int col, FiveChess fiveChess){
        List<ChessPoint> chessList = new ArrayList<>(8);
        char[][] chess = fiveChess.getChess();
        if (row < 15) {
            if(chess[row + 1][col] == 32) {
                chessList.add(new ChessPoint(row+1,col));
            }
        }

        if (col >= 1) {
            if(chess[row][col-1] == 32) {
                chessList.add(new ChessPoint(row,col-1));
            }
        }

        if (col < 15) {
            if(chess[row][col + 1] == 32) {
                chessList.add(new ChessPoint(row,col+1));
            }
        }

        if (row >= 1 && col >= 1) {
            if(chess[row-1][col+1] == 32) {
                chessList.add(new ChessPoint(row-1,col+1));
            }
        }

        if (row < 15 && col < 15) {
            if(chess[row + 1][col + 1] == 32) {
                chessList.add(new ChessPoint(row+1,col+1));
            }
        }

       if (row >= 1 && col >= 1) {
           if(chess[row-1][col-1] == 32) {
               chessList.add(new ChessPoint(row-1,col-1));
           }
       }

        if (row < 15 && col >= 1) {
            if(chess[row+1][col-1] == 32) {
                chessList.add(new ChessPoint(row+1,col-1));
            }
        }

        if (row >= 1) {
            if(chess[row-1][col] == 32) {
                chessList.add(new ChessPoint(row-1,col));
            }
        }
        return chessList;
    }
}
